package com.curvebreakers.wheresmystuff.model;


import com.curvebreakers.wheresmystuff.R;

import android.content.*;
import android.view.*;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class UserAdapter extends ArrayAdapter<User> {

	public UserAdapter(Context context, int textViewResourceId) {
		super(context, textViewResourceId);
	}
	
	public View getView(int position, View convertView, ViewGroup parent){

		View v = convertView;

		if (v == null) {
			LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			v = inflater.inflate(R.layout.listrow_user, null);
		}

		User u = getItem(position);
		
		if (u != null) {
			TextView userView = (TextView)v.findViewById(R.id.user_row_name);
			userView.setText(u.getEmail());
			v.findViewById(R.id.user_locked_flag).setVisibility((u.isLocked() ? View.VISIBLE : View.INVISIBLE));
			v.findViewById(R.id.user_admin_flag).setVisibility((u.isAdmin() ? View.VISIBLE : View.INVISIBLE));
		}
		
		return v;
	}
}
